import time
from time import sleep

from selenium.webdriver.support.select import Select

from Finance_fun.base.base import Base
from Finance_fun import page

"""以下为登录界面操作"""

class Page_Login(Base):
    # 点击登录链接
    def page_click_login_link(self):
        self.base_click(page.login_link)

    # 输入登录手机号
    def page_input_login_phone(self, phone):
        self.base_input(page.login_phone, phone)

    # 输入登录密码
    def page_input_login_password(self, password):
        self.base_input(page.login_password, password)

    def page_input_login_verify_code(self,code):
        self.base_input(page.login_verify_code,code)

    # 点击登录按钮
    def page_click_login_btn(self):
        self.base_click(page.login_btn)

    # 获取登录成功提示信息
    def page_get_login_success_inf(self):
        return self.base_get_text(page.login_success)

    # 获取登录错误(用户不存在、密码错误、用户名或密码为空)时的提示信息
    def page_get_login_err_inf(self):
        return self.base_get_text(page.login_error)

    # 判断元素是否存在
    def isElementExist(self):
        try:
            self.base_find_element(page.login_verify_code)
            return True
        except:
            return False


    """截图操作"""
    def page_get_screenshot(self):
        self.base_get_image()

    # 集成登录操作
    def page_login(self, phone, password):
        self.page_input_login_phone(phone)
        self.page_input_login_password(password)
        self.page_click_login_btn()
        sleep(1)

    # 集成登陆操作2
    def page_login_pwd_err(self,phone,password,code):
        self.page_input_login_phone(phone)
        self.page_input_login_password(password)
        time.sleep(3)
        self.page_input_login_verify_code(code)
        time.sleep(3)
        self.page_click_login_btn()
        sleep(1)